package com.legolas.consumer.web.controller;


import com.legolas.consumer.service.ConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;


@Controller
@RequestMapping("/test")
public class TestController {

    @Autowired
    ConsumerService consumerService;

    @RequestMapping("/testgroup1")
    @ResponseBody
    public Map<String, Object> tet(String name) {
        return consumerService.testGroup1(name);
    }

    @RequestMapping("/testgroup2")
    @ResponseBody
    public Map<String, Object> tet2(String name) {
        return consumerService.testGroup2(name);
    }

    @RequestMapping("/index")
    public String page() {
        return "index";
    }

    /**
     * 这里每次请求随机调用两个provider中的一个写入消息msg到同一个消息队列Consts.MQ_TEST_QUEUE_NAME中，
     * 然后立马在消费者中调用consum去消费掉它
     *
     * @param msg 要写入的消息
     * @return
     */
    @RequestMapping("/testQueueProducer1")
    @ResponseBody
    public String queueTest(String msg) {
        return consumerService.queueTest(msg);
    }

}
